import os

def split_lines(input_file, train_file, val_file):
    # 打开输入文件和输出文件
    with open(input_file, 'r', encoding='utf-8') as f, \
         open(train_file, 'w', encoding='utf-8') as train_f, \
         open(val_file, 'w', encoding='utf-8') as val_f:
        # 读取文件的所有行
        lines = f.readlines()
        # 分配单数行和双数行到不同的文件中
        for i, line in enumerate(lines):
            if i % 2 == 0:  # 单数行
                train_f.write(line)
            else:  # 双数行
                val_f.write(line)

# 设置输入文件和输出文件的路径
input_file = r'E:\postgraduate\大论文\seg_train\短数据集 500轮次\f_score.txt'
train_file = r'E:\postgraduate\大论文\seg_train\短数据集 500轮次\f_scores_train.txt'
val_file = r'E:\postgraduate\大论文\seg_train\短数据集 500轮次\f_scores_val.txt'

# 调用函数进行处理
split_lines(input_file, train_file, val_file)
